package _thread_lock._AQS;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: huangya
 * @Date: 2021/07/29
 * @Description:
 */
public class ReentrantLockTest {

    ReentrantLock lock = new ReentrantLock();

    public void test() throws InterruptedException {
        lock.lock();
        System.out.println("start");
        TimeUnit.SECONDS.sleep(200);
        System.out.println("end");
    }

    public void unlock() {
        lock.unlock();
    }

    public static void main(String[] args) throws InterruptedException {
        final ReentrantLockTest reentrantLockTest = new ReentrantLockTest();
        Thread t1 = new Thread(() -> {
            try {
                reentrantLockTest.test();

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        TimeUnit.SECONDS.sleep(5);

        reentrantLockTest.test();
    }
}
